I am trying to save an email from my mailbox .eml file (as a byte array into a SQL database).
However when running the following line of code, a 'TimeZoneConversionException' is thrown.
email.Load(new PropertySet(ItemSchema.MimeContent))
I can bind to the email and save attachments/subject/body etc but when trying to use the MIMEContent to save the email, I get the exception.Online searching shows it may be due to the DST settings on the server, but all DST updates have been installed on the server, and the email is a new one I create each time for testing.
The date in question is: "Unable to convert 2009-01-01T00:00:00.000 from (UTC+08:00) Perth to UTC.
The exception detail is:
Microsoft.Exchange.WebServices.Data.TimeZoneConversionException was unhandled by user code
HResult=-2146233088
Message=Unable to convert 2009-01-01T00:00:00.000 from (UTC+08:00) Perth to UTC.
Source=Microsoft.Exchange.WebServices
StackTrace:
at Microsoft.Exchange.WebServices.Data.EwsUtilities.ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone)
at Microsoft.Exchange.WebServices.Data.ExchangeServiceBase.ConvertDateTimeToUniversalDateTimeString(DateTime value)
at Microsoft.Exchange.WebServices.Data.EwsServiceXmlWriter.TryConvertObjectToString(Object value, String& strValue)
at Microsoft.Exchange.WebServices.Data.EwsServiceXmlWriter.WriteElementValue(XmlNamespace xmlNamespace, String localName, String displayName, Object value)
at Microsoft.Exchange.WebServices.Data.EwsServiceXmlWriter.WriteElementValue(XmlNamespace xmlNamespace, String localName, Object value)
at Microsoft.Exchange.WebServices.Data.AbsoluteDateTransition.WriteElementsToXml(EwsServiceXmlWriter writer)
at Microsoft.Exchange.WebServices.Data.ComplexProperty.WriteToXml(EwsServiceXmlWriter writer, XmlNamespace xmlNamespace, String xmlElementName)
at Microsoft.Exchange.WebServices.Data.ComplexProperty.WriteToXml(EwsServiceXmlWriter writer, String xmlElementName)
at Microsoft.Exchange.WebServices.Data.TimeZoneTransition.WriteToXml(EwsServiceXmlWriter writer)
at Microsoft.Exchange.WebServices.Data.TimeZoneDefinition.WriteElementsToXml(EwsServiceXmlWriter writer)
at Microsoft.Exchange.WebServices.Data.ComplexProperty.WriteToXml(EwsServiceXmlWriter writer, XmlNamespace xmlNamespace, String xmlElementName)
at Microsoft.Exchange.WebServices.Data.ComplexProperty.WriteToXml(EwsServiceXmlWriter writer, String xmlElementName)
at Microsoft.Exchange.WebServices.Data.TimeZoneDefinition.WriteToXml(EwsServiceXmlWriter writer)
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.WriteToXml(EwsServiceXmlWriter writer)
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.TraceAndEmitRequest(IEwsHttpWebRequest request, Boolean needSignature, Boolean needTrace)
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.BuildEwsHttpWebRequest()
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest& request)
at Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.InternalExecute()
at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalLoadPropertiesForItems(IEnumerable`1 items, PropertySet propertySet, ServiceErrorHandling errorHandling)
at Microsoft.Exchange.WebServices.Data.Item.InternalLoad(PropertySet propertySet)
at Microsoft.Exchange.WebServices.Data.ServiceObject.Load(PropertySet propertySet)
at EWSTest.Notifications.OnEvent(Object sender, NotificationEventArgs args) in C:\Users\ABhudia\Ash\TFS\VS2010\Exchange Web Service\PoC With Attachment\EWSTest\EWSTest_Console.cs:line 109
at Microsoft.Exchange.WebServices.Data.StreamingSubscriptionConnection.IssueNotificationEvents(GetStreamingEventsResponse gseResponse)
at Microsoft.Exchange.WebServices.Data.StreamingSubscriptionConnection.HandleServiceResponseObject(Object response)
at Microsoft.Exchange.WebServices.Data.HangingServiceRequestBase.ParseResponses(Object state)
InnerException: System.ArgumentException
HResult=-2147024809
Message=The supplied DateTime represents an invalid time. For example, when the clock is adjusted forward, any time in the period that is skipped is invalid.
Parameter name: dateTime
Source=mscorlib
ParamName=dateTime
StackTrace:
at System.TimeZoneInfo.ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone, TimeZoneInfoOptions flags, CachedData cachedData)
at System.TimeZoneInfo.ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone)
at Microsoft.Exchange.WebServices.Data.EwsUtilities.ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone)
InnerException:
I don't know where this date value is coming from - any suggestions?